clear all;
close all;

Xcomp = []; %Complexity = Number of nodes
YcompMax = []; %Complexity - maximum values
Ycomp = []; %Cell size 
ERRcomp = [];

Xerr=[];
Yerr=[];
Aerr=[];
W=[];
FMS=[];

dirnames=['lowres'];
dirs = cellstr(dirnames);

%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% GET DIRECTORIES %%%
%%%%%%%%%%%%%%%%%%%%%%%%%
for j=1:size(dirnames,1)
chdir(dirs(j){1});
i=0;
table = [];
table2=[];
do
	%Complexityfile
	filename = sprintf('%d_complexity_test.txt',i);

	d = load(filename);
	row = [];
	avg = mean(d);
	row = [avg min(d(:,5)) max(d(:,5)) std(d(:,5))];
	table=[table;row];

	%Accuracy file
	%
	%origin.x,origin.y,origin.a, 
	%matches.storage[0].x,matches.storage[0].y,matches.storage[0].a,matches.storage[0].weight, 
	%maxNumNodes, numLeafs, fms, ind, 
	%matches.storage[ind].x,matches.storage[ind].y,matches.storage[ind].a, matches.storage[ind].weight
	%
	filename = sprintf('%d_accuracy_test.txt',i);
	Accu = load(filename);
	row = [];
	%figure(i+10);
	%plot(Accu(:,2)-Accu(:,5)); %Y-virheen pysyvä poikkeama..
	xerr=(Accu(:,1)-Accu(:,4));
	yerr=(Accu(:,2)-Accu(:,5));
	aerr=(Accu(:,3)-Accu(:,6));
	row2=[];
	%average errors + average weight + average computing time
	row2=[mean(xerr) mean(yerr) mean(aerr) mean(Accu(:,7)) mean(Accu(:,10))];
	table2=[table2;row2];
	i++;
until(i>19)
%area = sqrt(table(:,1).*table(:,2));

%%%%%%%%% STORE COMPLEXITY NUMBERS %%%%%%
%Xcomp = [Xcomp area];
YcompMax = [YcompMax table(:,14)];
Ycomp =[Ycomp table(:,5)];
ERRcomp = [ERRcomp table(:,15)];

Xerr=[Xerr table2(:,1)];
Yerr=[Yerr table2(:,2)];
Aerr=[Aerr table2(:,3)];
W=[W table2(:,4)];
FMS=[FMS table2(:,5)];


cd ..
end

%even distr complexity
c = ((2 * table(:,1)./table(:,10)).^2).*(360);



%plot(area,table(:,5)) %Average
figure(1);
hold on;
plot(Ycomp);


legend('lowres','medres','highres','vhighres');
title('resolution Vs Complexity');
print -dpng 'reso_complex_plot.png'

figure(2);
hold on;
plot(YcompMax);
title('Resolution Vs Maximum Complexity')
legend('lowres','medres','highres','vhighres');
print -dpng 'reso_MaxComplex_plot.png'
%	errorbar(Ycomp,Xcomp,ERRcomp)

figure(3);
hold on;
plot(Xerr);
legend('lowres','medres','highres','vhighres');
title('x-err')
print -dpng 'reso_xerr.png'


figure(4);
hold on;
plot(Yerr);
legend('lowres','medres','highres','vhighres');
title('y-err')
print -dpng 'reso_yerr.png'

figure(5);
hold on;
plot(Aerr);
legend('lowres','medres','highres','vhighres');
title('A-err')
print -dpng 'reso_aerr.png'

figure(6);
hold on;
plot(W);
legend('lowres','medres','highres','vhighres');
title('Average weight')
print -dpng 'reso_weight.png'

figure(7);
%Accu = load('0_accuracy_test.txt');
hold on;
plot(Accu(:,7));
plot(Accu(:,16),'r');
title('Average Weight and Best weight (red)')
print -dpng 'weights.png'
